﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JQuery.Net;
using JQuery.Net.UI;

namespace TestFrame
{
    public partial class AutoCompleteDemo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            acCachedDemo.ClientCallback += new jQNetHandler(acCachedDemo_ClientCallback);
            acCustomTemplate.ClientCallback += new jQNetHandler(acCustomTemplate_ClientCallback);

            dtAnyTime.Value = DateTime.Now;
        }

        void acCustomTemplate_ClientCallback(object sender, jQNetArguments args)
        {
            switch (args.Event)
            {
                case jQNetEvents.source:
                    var data = new []
                    {
                        new 
                        { 
                            value = "jquery",
				            label = "jQuery",
				            desc  = "the write less, do more, JavaScript library",
				            icon  = Page.ResolveUrl("~/images/jquery_32x32.png")
                        },
                        new
                        {
				            value = "jquery-ui",
				            label = "jQuery UI",
				            desc  = "the official user interface library for jQuery",
				            icon  = Page.ResolveUrl("~/images/jqueryui_32x32.png")
			            },
                        new
			            {
				            value = "sizzlejs",
				            label = "Sizzle JS",
				            desc  = "a pure-JavaScript CSS selector engine",
				            icon  = Page.ResolveUrl("~/images/sizzlejs_32x32.png")
			            },
                        new 
                        {
                            value = "jquery.net",
                            label = "jQuery.Net",
                            desc  = "resource intelligent .net implementation JavaScript library",
                            icon  = ""
                        }

                    };

                    string term = (string)args["term"];

                    args.ResultData.Data = data.Where((X) => X.label.ToLower().StartsWith(term.ToLower())).ToArray();
                    break;
            }
        }

        void acCachedDemo_ClientCallback(object sender, JQuery.Net.UI.jQNetArguments args)
        {
            switch (args.Event)
            {
                case jQNetEvents.source:
                    var data = new string[] { "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl", "c#", "vb.net" };
                    var term = args.GetArgument<string>("term");

                    args.ResultData.Data = data.Where((Term) => Term.ToLower().StartsWith(term.ToLower())).ToArray();
                    break;
            }
        }
    }
}